﻿@{ ViewBag.Title = "Index";
    Layout = "~/Areas/Shared/_LayuiList.cshtml"; }

<input style="display: none" name="tbid" id="tbid" value="@ViewBag.tbid">

<!--数据表格-->
<table class="layui-hide" id="tableId" lay-filter="tableFilter"></table>

<script src="~/lib/layui/layui.js" charset="utf-8"></script>
<script>
    layui.use(["table", "form", "exLayer", "exUtils"], function () {
        let table = layui.table;
        let form = layui.form;
        let exLayer = layui.exLayer;
        let exUtils = layui.exUtils;
        let $ = layui.$;

        let ThisTable = table.render({
            elem: "#tableId",
            url: "/SysTable/TbSetUp/GetTableFieldsList?tbid=" + $("#tbid").val(),
            defaultToolbar: ['exports'],
            toolbar: "#toolbarTpl",
            cols: [[
                { type: "numbers", title: "NO.", fixed: 'left' },
                { field: "ColumnName", title: "列 名", width: 190, sort: true },
                { field: "DataType", title: "类 型", width: 120, sort: true },
                { field: "IndexName", title: "说 明", sort: true, width: layui.device().mobile ? 250 : null }
            ]],
            done: function (res, curr, count) {
                if (count == 0) {
                    $(".layui-btn").attr("class", "layui-btn layui-btn-warm layui-btn-sm");
                }
            },
            text: {
                none: '未创建数据表--请点击【创建数据表】按钮'
            }
        });

        table.on("toolbar(tableFilter)", function (obj) {
            switch (obj.event) {
                case "add":
                    add();
                    break;
            }
        });

        function add() {
            exUtils.ajax("/SysTable/TbBasic/CreatTableDB", "post", { tbid: $("#tbid").val().trim() }, true).done(function (response) {
                ThisTable.reload({
                    where: { tbid: $("#tbid").val().trim() }
                });
            }).fail(function (error) {
                console.log(error);
            });
            return false;
        }
    })
</script>
<!-- 头工具栏模板-->
<script type="text/html" id="toolbarTpl">
    <button class="layui-btn layui-btn-disabled layui-btn-sm" lay-event="add" id="add"><i class="fa fa-plus"></i>创建数据表</button>
</script>